const workRecords = require("../models/workRecords")
const user = require("../models/userDetail")
const homework = require("../models/homework")

var express = require('express');
var router = express.Router();
//  知识点标题  题目信息  应作人数  答对人数 正确率  题型
const formidable = require('formidable');

router.post('/', (req, res, next) => {
  var form = new formidable.IncomingForm();
  form.parse(req, async function (err, fields, files) {
    if (err) {
        res.json({ 'state': false })
    } else {
      let stu_flag = await homework.find({
        seq: fields.seq
      })
      let total_stu = await user.find({
        flags: {
          $all: stu_flag[0].flags
        }
      })
      let yethand_stu = await workRecords.find({
        seq: fields.seq
      })
      yethand_stu.forEach(ele => {
        let index = total_stu.findIndex(item => {
          return item.UUID === ele.UUID
        })
        total_stu.splice(index, 1)
      })

      res.json({ 'state': true, 'data': total_stu });
         
    }
  })
})

module.exports = router;